package com.ruoyi.web.controller.system;

import java.util.List;

import com.ruoyi.common.base.AjaxResult;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import com.ruoyi.common.config.Global;
import com.ruoyi.system.domain.SysMenu;
import com.ruoyi.system.domain.SysUser;
import com.ruoyi.system.service.ISysMenuService;
import com.ruoyi.framework.web.base.BaseController;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 首页 业务处理
 * 
 * @author ruoyi
 */
@Controller
@RequestMapping("/menu")
public class SysIndexController extends BaseController
{
    @Autowired
    private ISysMenuService menuService;

    // 系统首页
    @GetMapping("/index")
    public String index(ModelMap mmap)
    {
        // 取身份信息
        return "index";
    }

    // 系统介绍
    @GetMapping("/system/main")
    public String main(ModelMap mmap)
    {
        mmap.put("version", Global.getVersion());
        return "main";
    }

    @PostMapping("getMenu")
    @ResponseBody
    public AjaxResult getmMenu(HttpServletRequest request, HttpServletResponse response){
        // 取身份信息
        SysUser user = getSysUser();
        //根据角色查询menu
        List<SysMenu> menus = menuService.selectMenusByUser(user);
        return AjaxResult.success("操作成功",menus);
    }

}
